<!DOCTYPE html>
<#assign f = JspTaglibs["http://www.casic304.cn/f"] />
<#assign DutyDept = JspTaglibs["http://www.casic304.cn/DutyDept"]/>
<head>
    <meta charset="utf-8">
    <title>型号质量问题督办信息列表</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="${ctx}/layui/css/layui.css" media="all"/>
    <link rel="stylesheet" href="${ctx}/qbdmsStatic/iconfont/iconfont.css"/>
    <link rel="stylesheet" href="${ctx}/qbdmsStatic/style/qbdms.css">
    <script type="text/javascript">
        var __ctx = "${ctx}";
    </script>
</head>
<body class="listBody">
<div class="qbdms-list">
    <div class="layui-table-view-body">
        <table id="wQbdFalSuperviseTable" lay-filter="wQbdFalSuperviseTable"></table>
    </div>
</div>

<!-- 列表头部工具栏 -->
<script type="text/html" id="wQbdFalSuperviseHeaderToolsBar">
    <div class="ccpui-enterSel">
        <div class="layui-btn-container">
          <@f.a alias="xzan_xhzlwtdb1" css="layui-btn layui-btn-sm fillBtn" event="add" id="xz">
              <span>新增</span>
          </@f.a>
          <@f.a alias="scan_xhzlwtdb1" css="layui-btn layui-btn-sm" event="delete" id="sc">
              <span>删除</span>
          </@f.a>
            <!--            <a class="layui-btn layui-btn-sm" lay-event="export">-->
            <!--                <i class="layui-icon layui-icon-export"></i>-->
            <!--                <span>导出</span>-->
            <!--            </a>-->
            <!--            <a class="layui-btn layui-btn-sm" lay-event="import">-->
            <!--                <i class="layui-icon layui-icon-download-circle"></i>-->
            <!--                <span>导入</span>-->
            <!--            </a>-->
<!--            <@f.a alias="andb" css="layui-btn layui-btn-sm" event="suEdit" id="db">-->
<!--                <span>督办</span>-->
<!--            </@f.a>-->
            <@f.a alias="dban_xhzlwtdb1,dban_xhzlwtdb2" css="layui-btn layui-btn-sm" event="suEdit">
                <span>督办</span>
            </@f.a>

        </div>
        <form class="layui-form" action="" lay-filter="wQbdFalSuperviseQueryForm">
            <div class="layui-form-body selch">
                <div class="table-top-filter layui-row">

                    <div class="qbdms-listForm">
                        <label class="layui-form-label">型号名称</label>
                        <div class="layui-input-block">
                        <input type="text" class="layui-input filter-value" name="Q_fModelname_SL" placeholder="请输入"/>
                        </div>
                    </div>
                    <div class="qbdms-listForm">
                        <label class="layui-form-label">型号代号</label>
                        <div class="layui-input-block">
                        <select class="layui-input filter-value" name="Q_fModelsymbol_S" id="xh" lay-search="">

                        </select>
                        </div>
                    </div>

                    <div class="qbdms-listForm">
                        <label class="layui-form-label">问题责任单位</label>
                        <div class="layui-input-block">
                            <@DutyDept.dept css="layui-input filter-value" search=true db=true name="fDutydept" id="zrdw" showIn="0,1" verify="required"/>
                        </div>
                    </div>

                    <div class="qbdms-listForm">
                        <label class="layui-form-label">是否督办</label>
                        <div class="layui-input-block">
                        <select class="filter-value" name="Q_fIfsupervise_SL">
                            <option value=""></option>
                            <option value="下发成功">下发成功</option>
                            <option value="未下发">未下发</option>
                            <option value="下发失败">下发失败</option>
                        </select>
                        </div>
                    </div>

                </div>
                <div class="selchBtn">
                    <a class="layui-btn layui-btn-sm fillBtn" lay-event="query">
                        <span>查询</span>
                    </a>
                    <div class="layui-btn-group">
                        <button type="button" class="layui-btn layui-btn-sm" lay-event="clears" style="width: 28px;font-size: 12px;padding: 0">
                            <i class="iconfont data-iconcommon_refresh"></i>
                        </button>
                        <button type="button" class="layui-btn layui-btn-sm screenParent" lay-event="screen" style="width: 28px;font-size: 12px;padding: 0">
                            <i class="iconfont data-iconcommon_downarrow screen"></i>
                        </button>
                    </div>
                </div>
            </div>
        </form>

    </div>

</script>
<!-- 右侧工具栏 -->
<script type="text/html" id="wQbdFalSuperviseRightToolsBar">

    {{# if(d.fIfsupervise !== '下发成功' && d.createBy === '${userId}'){ }}
        <@f.a alias="bjan_xhzlwtdb1" css="RightBtn" event="edit">编辑</@f.a>
        <@f.a alias="scan_xhzlwtdb1" css="RightBtn" event="del">删除</@f.a>

    {{# } }}
       <a class="RightBtn" lay-event="particulars">详情</a>
    {{# if(d.fIfsupervise === '下发成功'){ }}
        <@f.a alias="gzan_xhzlwtdb1,gzan_xhzlwtdb2" css="RightBtn" event="track">跟踪</@f.a>
    {{# } }}

</script>

<script type="text/html" id="wQbdFalSuperviseRightToolsBar2">
    <a class="RightBtn" lay-event="particulars">详情</a>
    {{# if(d.fIfsupervise === '下发成功'){ }}
    <@f.a  alias="gzan_xhzlwtdb1,gzan_xhzlwtdb2" css="RightBtn" event="track">跟踪</@f.a>
    {{# } }}
</script>

<script src="${ctx}/qbdmsStatic/public/configFile.js"></script>
<script src="${ctx}/layui/layui.js"></script>
<script>
    //一般直接写在一个js文件中
    layui.config({
        base: serverPath.qbdmsPath + staticPath.qbdmsPath //静态资源所在路径
    }).extend({
        index: 'lib/index' //主入口模块
    }).use(['index', 'table', 'form', 'common','commonDialog', 'publicMethods', 'jquery', 'layer'], function () {
        var table = layui.table;
        var form = layui.form;
        var common = layui.common;
        var commonDialog = layui.commonDialog;
        var publicMethods = layui.publicMethods;
        var $ = layui.jquery;
        var layer = layui.layer;
        common.tableSort('wQbdFalSuperviseTable');

        function setEvaluateStatus(d){
            if(d.fIfsupervise=='未下发'){
                return '<i style="display: inline-block;margin-right:5px;width:6px;height:6px;background:rgba(38,130,255,1);border-radius:50%;"></i>'+ d.fIfsupervise
            }else if(d.fIfsupervise=='下发失败'){
                return '<i style="display: inline-block;margin-right:5px;width:6px;height:6px;background:#F04134;border-radius:50%;"></i>'+ d.fIfsupervise
            }else if(d.fIfsupervise=='下发成功'){
                return '<i style="display: inline-block;margin-right:5px;width:6px;height:6px;background:#67C23A;border-radius:50%;"></i>'+ d.fIfsupervise
            }else if(d.fIfsupervise=='下发中'){
                return '<i style="display: inline-block;margin-right:5px;width:6px;height:6px;background:#67C23A;border-radius:50%;"></i>'+ d.fIfsupervise
            } else {
                return '';
            }
        }


        var tableH = publicMethods.tabHeight();

        var cols = '${cols}';
        var currentSystemLevel = "${currentSystemLevel}";
        var commonCols = [
            //表头
            {type: 'checkbox', fixed: 'left'}
            ,{field: 'sn', type: 'numbers', title: '序号', fixed: 'left'}
            , {field: 'fModelname', title: '型号名称', sort: false, sortname: 'f_modelname',minWidth:'100'}
            , {field: 'fModelsymbol', title: '型号代号', sort: false, sortname: 'f_modelsymbol',minWidth:'100'}
            , {field: 'fDutydept', title: '问题责任单位', sort: false, sortname: 'f_dutydept',minWidth:'120'}
            , {field: 'fFailuredescription', title: '问题现象', sort: false, sortname: 'f_failuredescription',minWidth:'300'}
        ];
        var diyCols = [];
        if ("PLANTLEVEL" !== currentSystemLevel) {
            diyCols = [{field: 'fIfsupervise', title: '是否督办', sort: false, sortname: 'f_ifsupervise',minWidth:'100',templet:setEvaluateStatus}];
        }



        var manageCols = [{
            fixed: 'right',
            title: '管理',
            toolbar:  ("${currentSystemLevel}" === 'GROUPLEVEL') ? '#wQbdFalSuperviseRightToolsBar' : '#wQbdFalSuperviseRightToolsBar2'
        }];
        var totalCols= [];

        totalCols = totalCols.concat(commonCols).concat(diyCols).concat(manageCols);

        //第一个实例
        window.tableInstace =  table.render({
            elem: '#wQbdFalSuperviseTable'
            , height: tableH
            , url: serverPath.qbdmsPath + '/qbdms/wQbdFalSupervise/list'
            ,page: publicMethods.pageFun() //开启分页
            , toolbar: '#wQbdFalSuperviseHeaderToolsBar'
            , defaultToolbar: ['']
            , limit:20
            , method: 'post'
            , autoSort: false //是否排序
            , cols: [cols ? JSON.parse(cols) : totalCols], done: function () {
                common.tableSelectCon('.ccpui-enterSel .layui-form input','a[lay-event=query]','.ccpui-enterSel');
            }
            ,parseData: function(res){ //res 即为原始返回的数据
                common.parseDataList(res,['fModelname','fModelsymbol','fDutydept','fIfsupervise']);
                return {
                    "code": res.code, //解析接口状态
                    "msg": res.msg, //解析提示文本
                    "count": res.count, //解析数据长度
                    "data": res.data //解析数据列表
                };
            }
        });

        //list页面初始化展开按钮tips展示（展开按钮类名）
        publicMethods.tipsAuto('.screen')
        //筛选条件初始化（页面表格的Id，是否初始化（true、false））
        common.initScreenTop('wQbdFalSuperviseTable',true);

        function setXhdh(data) {
            // 型号代号
            var xhdh = ${wQbdXhdhs};
            var xhdhHtml = "<option value=\"\"></option>";
            $.each(xhdh, function (index, obj) {
                xhdhHtml += "  <option  xhmc='" + obj.fModelname + "' value='" + obj.fModelcode + "'  >" + obj.fModelcode + "</option>";
            });
            $("select[name='Q_fModelsymbol_S']").html(xhdhHtml);
            if(data !== null && data !== undefined && data !==""){
                $("#xh").val(data);
            }
        }



        function pd(){
            if ("HOSPITALLEVEL" === currentSystemLevel) {
                // 二级单位
                $("#xz").addClass("layui-hide");
                $("#sc").addClass("layui-hide");
            } else if("PLANTLEVEL" === currentSystemLevel){
                // 三级单位
                // 隐藏搜索 责任单位
                $("#zrdw").removeClass();
                $("#zrdw").addClass("layui-hide");
                $("#sfdb").removeClass();
                $("#sfdb").addClass("layui-hide");
                // 隐藏督办
                $("#db").addClass("layui-hide");
                // 隐藏 新增
                $("#xz").addClass("layui-hide");
                // 隐藏删除
                $("#sc").addClass("layui-hide");
            }
        }

        function suEdit(datas) {
            if(datas.length < 1){
                layer.confirm(publicMethods.confirmStyle("请选择一条数据!"),{title: false,skin: 'confirm-class'});
                return;
            }
            // 获取需要督办的id
            var ids = [];
            $.each(datas, function (index, obj) {
                ids.push(obj.id);
            });

            // 集团级不需要选择框
            if ("GROUPLEVEL" === currentSystemLevel) {
                var data = {"ids":ids.join()};
                db(data);
                pd();
            }


            if("HOSPITALLEVEL" === currentSystemLevel){
                var paramValueString = "";
                commonDialog.CommonDialog("bmxzq",  function (data,selectIds) {
                    // console.log(ids);
                    var dataObj = JSON.parse(data);
                    var data = {"ids":ids.join(),"dbDept":dataObj.ORGNAME,"dbDeptId":dataObj.ORGID};
                    // console.log();
                    db(data);
                    //对象赋值
                }, paramValueString);
            }


        }

        function db(data){
            var load = layer.load(1);
            $.ajax({
                type: "POST",
                url: "${ctx}/qbdms/wQbdFalSupervise/suEdit",
                data: data,
                success: function (data) {
                    layer.confirm(publicMethods.confirmStyle(data),{title: false,skin: 'confirm-class'});
                    // 执行重载
                    reflashQuery(true);
                    pd();
                    layer.close(load);

                },
                error: function () {
                    //函数体，数据发送错误时执行
                    reflashQuery(true);
                    pd();
                    layer.close(load);
                }
            });
        }

        if ("PLANTLEVEL" === currentSystemLevel) {
            // $("a[lay-event='add']").hide();
            // zlwtsymx 三院明细
            $("#wQbdFalSuperviseRightToolsBar2").html(
                '<@f.a alias="xjzlwt_xhzlwtdb3y" event="addSanYuan" css="RightBtn" ><span>新建质量问题</span> </@f.a>' +
                '<@f.a alias="xjzlwt_xhzlwtdb3" css="RightBtn" event="build">新建质量问题</@f.a>' +
                "<a class='RightBtn' lay-event='relation'>关联质量问题</a>" +
                "<a class='RightBtn' lay-event='particulars'>明细 </a>"
            )
        }

        function reflashQuery(isClear) {
            var xh = $("#xh").val();
            var org = $("#org").val();
            common.tableConditionRender("wQbdFalSuperviseTable", "wQbdFalSuperviseQueryForm", {where: {}}, isClear);
            if(!isClear){
                setXhdh(xh);
            }

        }

        table.on('toolbar(wQbdFalSuperviseTable)', function (obj) {
            var checkStatus = table.checkStatus(obj.config.id);
            var data = checkStatus.data;
            var _this = this;
            var layerH=publicMethods.layHeight('.listBody');
            switch (obj.event) {
                case 'add':
                    window.location.href = serverPath.qbdmsPath + "/qbdms/wQbdFalSupervise/view/add";
                    break;
                case 'delete':
                    var array = "";
                    for (var i = 0; i < data.length; i++) {
                        array += data[i].id + ",";
                    }
                    delFun(data, array);
                    break;
                case 'export':
                    if (data.length == 0) {
                        layer.confirm(publicMethods.confirmStyle('还没有选择，是否导出全部?'),{title: false,skin: 'confirm-class'}, function (index) {
                            layer.close(index);
                            var url = serverPath.qbdmsPath + '/qbdms/wQbdFalSupervise/exportData';
                            $("form[lay-filter='wQbdFalSuperviseQueryForm']").find(".filter-value").each(function (i, value) {
                                if (i == 0) {
                                    url += "?" + this.name + "=" + this.value
                                } else {
                                    url += "&" + this.name + "=" + this.value
                                }
                            });
                            window.location.href = url;
                        });
                    } else {
                        layer.confirm(publicMethods.confirmStyle('确定导出吗?'),{title: false,skin: 'confirm-class'}, function (index) {
                            layer.close(index);
                            var ids = [];
                            for (var i = 0; i < data.length; i++) {
                                ids.push(data[i].id);
                            }
                            var url = serverPath.qbdmsPath + '/qbdms/wQbdFalSupervise/exportData?id=' + ids;
                            window.location.href = url;
                        });
                    }
                    break;
                case "import":
                    common.importInit('wQbdFalSuperviseTable',"/qbdms/wQbdFalSupervise/importData",false,"");
                    dateReflash();
                    break;
                    /*layer.open({
                        type: 2,
                        title: "导入",
                        shade: 0.3,
                        area: ['400px', '300px'],
                        content: serverPath.qbdmsPath + "/qbdms/wQbdFalSupervise/view/import"
                        , end: function () {
                            table.reload('wQbdFalSuperviseTable', {
                                page: {
                                    curr: 1
                                }
                            });

                        }
                    });
                    break;*/
                case "query":
                    reflashQuery(false);

                    pd();
                    break;
                case "clears":
                    reflashQuery(true);

                    setXhdh();

                    form.render();
                    pd();
                    break;
                case "screen":
                    common.initScreenTop('wQbdFalSuperviseTable');

                    form.render();
                    break;
                case "suEdit":
                    reflashQuery(false);

                    suEdit(data);
                    pd();
                    break;
                case "listStyle":
                    layer.open({
                        type: 2,
                        area: ['80%', layerH],
                        skin: 'qbdms-layerFormBtn',
                        title: ['新增列表样式', 'font-size:14px;'],
                        content: __ctx + '/qbdms/wCustomColumns/view/list',
                        success:function (layero, index) {
                            publicMethods.tipsAuto(layero.find('.layui-layer-setwin'),'点击这里关闭弹框哦',2000)
                        }
                    });
                    break;
            }
        });


        table.on('sort()', function(obj){
            reflashQuery(false);
            pd();
        });

        function track(id,fDutydept){
            var layerH=publicMethods.layHeight('.listBody');
            $.ajax({
                url: serverPath.qbdmsPath + '/qbdms/wQbdFalProblemreset/list?fSuperviseid='+ id+'&mark=track',
                type: "post",
                dataType:'json',
                success: function (data) {
                    if(data.data.length > 0){
                        layer.open({
                            type: 2,
                            area: ['80%', layerH],
                            title: ['跟踪质量问题信息'],
                            // btn: ['关闭'] ,
                            content: serverPath.qbdmsPath + '/qbdms/wQbdFalSupervise/view/track?did=' + id+'&mark=track'
                        });
                    } else {
                        layer.alert(publicMethods.confirmStyle(fDutydept + ' 单位暂未反馈'),{title: false,skin: 'confirm-class'});
                        // layer.open({
                        //     title: '提示'
                        //     , content: fDutydept + ' 单位暂未反馈'
                        // });
                    }
                },
                error: function (XMLHttpRequest, textStatus, errorThrown) {
                    // console.log(XMLHttpRequest);
                    // console.log(textStatus);
                }
            })



        }

        table.on('tool(wQbdFalSuperviseTable)', function (obj) {
            var data = obj.data, //获得当前行数据
                layEvent = obj.event; //获得 lay-event 对应的值
            var layerH=publicMethods.layHeight('.listBody');

            switch (layEvent) {
                case "edit":
                    window.location.href = serverPath.qbdmsPath + '/qbdms/wQbdFalSupervise/view/add?id=' + data.id;
                    break;
                case "particulars":
                    window.location.href = serverPath.qbdmsPath + '/qbdms/wQbdFalSupervise/view/particulars?id=' + data.id;
                    break;
                case "build":
                    window.location.href = serverPath.qbdmsPath + '/qbdms/wQbdFalProblemreset/view/add?did=' + data.id;
                    break;
                case 'addSanYuan':
                    window.location.href = serverPath.qbdmsPath + '/qbdms/wQbdFalProblemreset/view/addSanYuan?did=' + data.id;
                    break;
                case "particularsSanYuan":
                    window.location.href =  serverPath.qbdmsPath + '/qbdms/wQbdFalProblemreset/view/particularsSanYuan?id='+data.id;
                    break;
                case "relation":
                    layer.open({
                        type: 2,
                        area: ['80%', layerH],
                        title: ['关联质量问题'],
                        // btn: ['关闭'] ,
                        content: serverPath.qbdmsPath + '/qbdms/wQbdFalSupervise/view/relation?did=' + data.id
                    });
                    break;
                case "track":
                    track(data.id,data.fDutydept);

                    break;
                case "del":
                    delFun(data, data.id);
                    break;
            }
        });

        function delFun(data, id) {
            if (data.length === 0) {
                layer.confirm(publicMethods.confirmStyle("请先选择一行数据!"),{title: false,skin: 'confirm-class'});
            } else {
                layer.confirm(publicMethods.confirmStyle('确定删除当前数据吗?'),{title: false,skin: 'confirm-class'},function (index) {
                    layer.close(index);
                    $.ajax({
                        url: serverPath.qbdmsPath + "/qbdms/wQbdFalSupervise/del",
                        type: "post",
                        data: {id: id},
                        dataType: 'json',
                        success: function (data) {
                            layer.confirm(publicMethods.confirmStyle(data.msg),{title: false,skin: 'confirm-class'});
                            //执行重载
                            reflashQuery(true);

                        },
                        error: function (XMLHttpRequest, textStatus, errorThrown) {
                            layer.confirm(publicMethods.confirmStyle(data.msg),{title: false,skin: 'confirm-class'});
                            //执行重载
                            reflashQuery(true);

                        }
                    })
                })
            }
        }

        /*刷新时间控件*/
        common.tableSort("wQbdFalSuperviseTable", {show: window.Initialization});

        setXhdh();
        pd();

        form.render();
        common.tableSort("wQbdFalSuperviseTable");
    });
</script>

</body>
</html>